/*
 * MIT License
 *
 * Copyright (c) 2020 wen.gu <454727014@qq.com>
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */

/***************************************************************************
 * Name: boot_manager.h
 *
 * Purpose: boot manager implementation
 *
 * Developer:
 *   wen.gu , 2020-9-02
 *
 * TODO:
 *
 ***************************************************************************/

/******************************************************************************
 **    INCLUDES
 ******************************************************************************/
#ifndef __PANDA_BOOT_MANAGER_H__
#define __PANDA_BOOT_MANAGER_H__

#include "panda/core/types.h"
#include "panda/core/errors.h"
#include "panda/com/service_provider.h"

namespace panda
{
/******************************************************************************
 **    MACROS
 ******************************************************************************/

/******************************************************************************
 **    TYPE DEFINITIONS
 ******************************************************************************/

/******************************************************************************
 **    CLASSES/FUNCTIONS DEFINITIONS
 ******************************************************************************/
#if 0
class CORE_CLASS BootManager
{
public:
    using PandaErrc = panda::core::PandaErrc;
public:
    BootManager();
    ~BootManager();

public:
    bool initialize();
    bool start();
    bool stop();

protected:

    /** boot a target
     * reqHdlr [in] response handle
     * method  [in] method name
     * param   [in] the parameter for request   
     *              [mandatory ] name:  the name of boot target
     *              [optional]   path:  the path of boot target
     *              [optional]   param: the boot parameter for target
     *              [optional]   log_redirect: redirect stdio output
     *              [optional]   dependence: the dependence for target.
     *
     * reply   [out]: code : error code
     *                descroption: the descriptor for error code
     */
    PandaErrc bootTarget(std::shared_ptr<ServiceJsonRequestHandle> reqHdl,
                         const std::string& method, const Value& param);

    /** suspend a target
    * reqHdlr [in] response handle
    * method  [in] method name
    * param   [in] the parameter for request
    *              [mandatory ] name:  the name of boot target
    *
    * reply   [out]: code : error code
    *                descroption: the descriptor for error code
    */
    PandaErrc suspendTarget(std::shared_ptr<ServiceJsonRequestHandle> reqHdl,
                            const std::string& method, const Value& param);

    /** resume a target
    * reqHdlr [in] response handle
    * method  [in] method name
    * param   [in] the parameter for request
    *              [mandatory ] name:  the name of boot target
    *
    * reply   [out]: code : error code
    *                descroption: the descriptor for error code
    */
    PandaErrc resumeTarget(std::shared_ptr<ServiceJsonRequestHandle> reqHdl,
                           const std::string& method, const Value& param);

 
    /** stop a target
     * reqHdlr [in] response handle
     * method  [in] method name
     * param   [in] the parameter for request
     *              [mandatory ] name:  the name of boot target
     *
     * reply   [out]: code : error code
     *                descroption: the descriptor for error code
     */
    PandaErrc stopTarget(std::shared_ptr<ServiceJsonRequestHandle> reqHdl,
                        const std::string& method, const Value& param);

    /** reboot a target
     * reqHdlr [in] response handle
     * method  [in] method name
     * param   [in] the parameter for request
     *              [mandatory ] name:  the name of boot target
     *
     * reply   [out]: code : error code
     *                descroption: the descriptor for error code
     */
    PandaErrc rebootTarget(std::shared_ptr<ServiceJsonRequestHandle> reqHdl,
                           const std::string& method, const Value& param);

    /** add a item to boot list
     * reqHdlr [in] response handle
     * method  [in] method name
     * param   [in] the parameter for request
     *              [mandatory ] name:  the name of boot target
     *              [optional]   path:  the path of boot target
     *              [optional]   param: the boot parameter for target
     *              [optional]   log_redirect: redirect stdio output
     *              [optional]   dependence: the dependence for target.
     *
     * reply   [out]: code : error code
     *                descroption: the descriptor for error code
     */
    PandaErrc addBootItem(std::shared_ptr<ServiceJsonRequestHandle> reqHdl,
                           const std::string& method, const Value& param);
    

    /** remove a item from boot list
     * reqHdlr [in] response handle
     * method  [in] method name
     * param   [in] the parameter for request
     *              [mandatory ] name:  the name of boot target
     *
     * reply   [out]: code : error code
     *                descroption: the descriptor for error code
     */
    PandaErrc removeBootItem(std::shared_ptr<ServiceJsonRequestHandle> reqHdl,
                             const std::string& method, const Value& param);

    /** update a boot item in boot list
     * reqHdlr [in] response handle
     * method  [in] method name
     * param   [in] the parameter for request
     *              [mandatory ] name:  the name of boot target
     *              [optional]   path:  the path of boot target
     *              [optional]   param: the boot parameter for target
     *              [optional]   log_redirect: redirect stdio output
     *              [optional]   dependence: the dependence for target.
     *
     * reply   [out]: code : error code
     *                descroption: the descriptor for error code
     */
    PandaErrc updateBootItem(std::shared_ptr<ServiceJsonRequestHandle> reqHdl,
                             const std::string& method, const Value& param);


    /** query boot item from boot list
     * reqHdlr [in] response handle
     * method  [in] method name
     * param   [in] the parameter for request
     *              [mandatory ] name:  the name of boot target
     *
     * reply   [out]: [mandatory ] code : error code
     *                [mandatory ] descroption: the descriptor for error code
     *                [mandatory ] name:  the name of boot target
     *                [optional]   path:  the path of boot target
     *                [optional]   param: the boot parameter for target
     *                [optional]   log_redirect: redirect stdio output
     *                [optional]   dependence: the dependence for target.
     */
    PandaErrc queryBootItem(std::shared_ptr<ServiceJsonRequestHandle> reqHdl,
                             const std::string& method, const Value& param);

    /** querty boot state
     * reqHdlr [in] response handle
     * method  [in] method name
     * param   [in] the parameter for request
     *              [mandatory ] name:  the name of boot target
     *
     * reply   [out]: [mandatory ] code : error code
     *                [mandatory ] descroption: the descriptor for error code
     *                [optional]   state: the state of current boot item
     *                             0: not boot yet
     *                             1: is running
     *                             2: suspend state.
     *                
     */
    PandaErrc queryBootState(std::shared_ptr<ServiceJsonRequestHandle> reqHdl,
                             const std::string& method, const Value& param);

protected:

private:
    ServiceJson* mSrv = nullptr;
    std::string mComType;
    std::string mBootListConf;
    Value mBootList;
};
#endif
} /** namespace panda*/

#endif /** !__PANDA_BOOT_MANAGER_H__ */